package com.dataeco.api.repository;

import com.dataeco.api.entity.UsersRoles;
import com.dataeco.api.entity.UserRoleKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;


public interface UsersRolesRepository extends JpaRepository<UsersRoles,UserRoleKey>{

    @Query("select ur from UsersRoles ur where ur.userRoleKey.user.id=:userId and ur.userRoleKey.dataecoRole.id=:roleId")
    UsersRoles findByUserIdAndRoleId(@Param("userId") String userId, @Param("roleId") String roleId);

    @Query("select ur from UsersRoles ur")
    List<UsersRoles> findAllUsersAndRoles();

    @Query("select ur from UsersRoles ur where ur.userRoleKey.user.id=:userId")
    List<UsersRoles> findByUserId(@Param("userId") String userId);

    @Query("select ur from UsersRoles ur where ur.userRoleKey.dataecoRole.id=:roleId")
    List<UsersRoles> findByRoleId(@Param("roleId") String roleId);

    @Query("select ur from UsersRoles ur where ur.userRoleKey.dataecoRole.id in :roleIds")
    List<UsersRoles> findInRoleIds(@Param("roleIds") String[] roleIds);


}
